/* eslint-disable react/react-in-jsx-scope */
import { hasToken } from '@/utils/storage'
import { Route, Redirect, RouteProps } from 'react-router-dom'

export const PrivateRoute = ({ children, ...rest }:RouteProps) => {
  return (
       <Route
       {...rest}
       render={props => {
         if (hasToken()) {
           return children
         }

         return (
             <Redirect
             to={{
               pathname: '/login',
               state: {
                 from: props.location.pathname // 回跳地址
               }
             }}
             />
         )
       }}

       />
  )
}
